package cn.java78.jdbc;

import cn.myschool.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class UpdateStudent2 {
    public static void main(String[] args) {
        //根据学号修改名字
        Connection connection = null;
        PreparedStatement st = null;
        try {
            connection = DBUtil.getConnection();
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入学生的新名字：");
            String newName= sc.nextLine();
            //newName=newName.replace(",","\'");
           // newName=newName.replace("#","\\#");
            System.out.println("请输入学号");
            long stuno = sc.nextLong();
            //insert into s(id,xx)values(?,?,?,?_:
            String sql = "update s_student set sname=?  where stuno=?";
            System.out.println(sql);
            st = connection.prepareStatement(sql);
            st.setString(1,newName);
            st.setLong(2,stuno);
            int i = st.executeUpdate();//不需要sql
            System.out.printf("xiugai了%d条", i);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(null, st, connection);
        }


    }
}
